package com.gitee.sparta.core.listener;

import com.gitee.sparta.core.bean.event.SingleServerEnableEvent;
import com.gitee.sparta.core.process.workers.SpartaCarryWorker;
import com.gitee.sparta.core.property.SpartaCoreProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;


/**
 * 单机服务启动监听器
 *
 * @author zyred
 * @since v 1.0.0
 */
@Slf4j
@AllArgsConstructor
public class SingleServerEnableEventListener<V> implements ApplicationListener<SingleServerEnableEvent> {

    private final SpartaCarryWorker<V> spartaCarryWorker;


    @Override
    public void onApplicationEvent(SingleServerEnableEvent e) {
        this.spartaCarryWorker.start();

        Object source = e.getSource();
        if (source instanceof SpartaCoreProperties) {
            SpartaCoreProperties pro = (SpartaCoreProperties) source;
            log.info("[Sparta] {} started.", pro.getSystemName());
        }
    }
}
